<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>发放停车券</title>
<link rel="stylesheet"
	href="${ctx}/static/plug/frozenui-1.3.0/css/frozen.css" media="all">
<link rel="stylesheet" href="${ctx}/static/css/coupon/releaseCoupon.css"
	media="all">
	<style type="text/css">
		.ui-switch input:checked:before{
			border-color:#f3a621;
			box-shadow:#f3a621 0px 0px 0px 16px inset;
			background-color:#f3a621;
		}
	</style>
</head>

<body>	

	 <div class="ui-form-item ui-form-item-switch ui-border-b">
          <p>
              一码多扫
          </p>
          <label class="ui-switch">
              <input id="sweepCode" type="checkbox"  checked="checked">
          </label>
      </div>

	<section class="ui-container">
		<div class="ui-flex  ui-flex-ver ui-flex-pack-center content"
			id="moneyDetailDiv">


			<c:if
				test="${shopCouponVos != null &&  fn:length(shopCouponVos) > 0 }">
				<c:forEach var="shopCouponVo" items="${shopCouponVos}">
					<div class="div-content" id="div-shop-coupon-${shopCouponVo.id}"
						onclick="funcReleaseCoupon(this,'${shopCouponVo.encryptParams}',${shopCouponVo.useType})">
						<ul class="ui-row-flex">
							<li class="ui-col  ui-col-3">
								<div class=""
									style="padding-top: 0px; padding-bottom: 10px; padding-left: 15px; width: 100%">
									<h2 style="font-size: 25px;" class="coupon-money">
										<c:if test="${shopCouponVo.couponMoneyType == 1}">
						                ￥<fmt:formatNumber type="number" value="${shopCouponVo.money}"   pattern="0.00" maxFractionDigits="2"/>
						                </c:if>
						                <c:if test="${shopCouponVo.couponMoneyType == 2}">
						                全免券
						                </c:if>
									</h2>
									<br>
									<h1 style="font-size: 15px;" class="coupon-type-desc">${shopCouponVo.couponRule}</h1>
								</div>
							</li>
						</ul>
					</div>
				</c:forEach>
			</c:if>

		</div>

	</section>

	<section id="dialog">
		<div class="demo-block">
			<div class="ui-dialog ">
				<div class="ui-dialog-cnt" style="width: 350px">
					<div class="ui-dialog-bd">
						<h4 id="imgTypeMoney"></h4>
						<h5 id="imgTypeDesc"></h5>
						<div id="confirmMessage" align="center">
							<img style="width: 250px; height: 250px" id="imgQRCODE" src="" />
						</div>
					</div>
					<div class="ui-dialog-ft">
						<button type="button" id="btnCancel" data-role="button">取消</button>
					</div>
				</div>
			</div>
		</div>
	</section>

</body>
<script src="${ctx}/static/plug/frozenui-1.3.0/lib/zepto.min.js"></script>
<script src="${ctx}/static/plug/frozenui-1.3.0/js/frozen.js"></script>
<script>
	var paramObj = {
		"parkingLotCouponsParams" : "${parkingLotCouponsParams}",
		"generalQRCodeParams" : "${generalQRCodeParams}"
	};

	$(function() {
		$("#btnCancel").click(function() {
			$(".ui-dialog").removeClass("show");
		});
	});

	function funcReleaseCoupon(obj, encryptParams, sueess) {
			var moneyDesc = $(obj).find(".coupon-money").html();
			var typeDesc = $(obj).find(".coupon-type-desc").html();
			console.log(moneyDesc + "-" + typeDesc);
			if (!encryptParams) {
				showTips("info", "生成二维码失败,请重试");
				return;
			}
			var sweepCode;
			if($("#sweepCode").prop("checked")){
				sweepCode = 2;
			}else {
				sweepCode = 1;
			}
			var param = {
				"params" : encryptParams,
				"sweepCode" : sweepCode
			};
			canDelete = false;
			$.post("${action}", param, function(obj) {
				if(obj.states){
					showTips("info", "发放停车劵金额达到上限");
					return;
				}
				if (obj.result) {
					//console.log(obj.data);
					if(moneyDesc != '0.00'){
						$("#imgTypeMoney").html("" + moneyDesc + "停车券");
					}else {
						$("#imgTypeMoney").html("全免"+ "停车券");
					}
					
					$("#imgTypeDesc").html(typeDesc);
					$('#imgQRCODE').attr('src',
							'data:image/jpg;base64,' + obj.data);
					$(".ui-dialog").addClass("show");
				} else {
					showTips("info", "生成二维码失败,请重试");
				}
			});
	}

	function confirmDelCarNo(couponId) {

		$(".ui-dialog").addClass("show");
		$("#btnConfirm").bind("click", function() {
			deleteShopCoupon(couponId);
		});
	}

	var canDelete = true;
	function deleteShopCoupon(couponId) {
		if (canDelete) {
			console.log("couponId:" + couponId);
			var param = {
				"params" : paramObj.delShopCouponParams,
				"couponId" : couponId,
			};
			canDelete = false;
			$.post("${action}", param, function(obj) {
				$(".ui-dialog").removeClass("show");
				if (obj.result) {
					showTips("info", "删除成功");
					$("#div-shop-coupon-" + couponId).remove();
				} else {
					$("#showMsgP").html(obj.msg);
				}
				canDelete = true;
			});
		}
	}

	function funcMyReleaseCoupon() {
		var hrefUrl = "${action}?params=" + paramObj.parkingLotCouponsParams;
		window.location.href = hrefUrl;
	}
</script>
</html>
